package logic

import (
	"context"
	"srv/models/mysql"

	"srv/internal/svc"
	"srv/sesame"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsInfLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsInfLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsInfLogic {
	return &GoodsInfLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsInfLogic) GoodsInf(in *sesame.GoodsInfoRequest) (*sesame.GoodsInfo, error) {
	// todo: add your logic here and delete this line
	g := mysql.Goods{}
	err := g.GetGoods(in.GoodsId)
	if err != nil {
		logx.Error("商品不存在")
		return nil, err
	}
	return &sesame.GoodsInfo{
		GoodsTitle: g.GoodsTitle,
		GoodsStock: int64(g.GoodsStock),
		GoodsCover: g.GoodsCover,
		GoodsPrice: float32(g.GoodsPrice),
		GoodsSales: int64(g.GoodsSales),
	}, nil
}
